package com.hf.www.base.controller;

import com.hf.www.base.common.BaseController;
import com.hf.www.base.common.Pager;
import com.hf.www.base.model.SysConfigModel;
import com.hf.www.core.plugin.annotation.Control;
import com.jfinal.log.Logger;
import com.jfinal.plugin.activerecord.Page;


@Control(controllerKey="/sysCfg")
public class SysConfigController extends BaseController{

	private static final Logger LOG = Logger.getLogger(SysConfigController.class);
	
	
	public void index(){
		
		
		render("system/sys_config");
	}
	
	
	
	public void list() {
		Pager pager = createPager("keyword" , "state" );

		Page<?> page = SysConfigModel.dao.page(pager);

		setAttr("total",page.getTotalRow());
		setAttr("rows",page.getList());
		
		
		
		renderJson();
	}
	
	
	
	public void save(){
		
		try {
			
			SysConfigModel  config = getModelWithOutModelName(SysConfigModel.class, true);
			
			if(config.get("id") != null){
				
				config.update();

			}else{
				config.save();
			}
			
			setAttr("r" , true) ;
			setAttr("m" , "保存数据成功！" );
			
		} catch (Exception e) {
			
			setAttr("r" , false );
			setAttr("m" , "保存数据失败！");
			LOG.error("系统数据配置-保存数据失败！" , e);
		}
		
		renderJson();
	}
	
	
	public void toEdit(){
		
		setAttr("config", SysConfigModel.dao.findById(getPara("id")));
		render("system/sys_config_edit");
		
	}
	
	
	public void batchDel(){
		
		try {
			
			SysConfigModel.dao.batchDel(getPara("ids"));
			setAttr("r" , true) ;
			
		} catch (Exception e) {
			
			setAttr("r" , false);
			setAttr("m" , "删除数据配置失败！");
			LOG.error("删除数据配置失败！" , e);
		}
		
		renderJson();
	}
	
	
}
